﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Core
{
    static class RSA
    {
        /// <summary> 
        /// RSA加密 
        /// </summary>
        public static string EncryptString(string sSource, string sPublicKey)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            rsa.FromXmlString(sPublicKey);
            byte[] cipherbytes = rsa.Encrypt(Encoding.UTF8.GetBytes(sSource), true);
            return Convert.ToBase64String(cipherbytes);
        }
        public static string EncryptString(string sSource)
        {
            return EncryptString(sSource, YarmuRSAPublicKey);
        }

        public const string YarmuRSAPublicKey =
            "<RSAKeyValue><Modulus>wGuxK5RiMap/yEbEYqFrsSv2pCDbzOZvCpe84OswxGZZZHDOXEMpGcYQyI" +
            "C4fIPYCojZIgpkokd/3NKD7DP4wMG0h50dBWRJ3W7/f3mkJusf+IV4feg9h3wimEYE0lBHTRA9PXZfd4" +
            "SP97VAh/2cRhDgOJ+DNvMdRWQXcgQpCLbTLAE8C0oEi5UWgUU/qC4LioovP1iE527NF8paEJ3oPzsbix" +
            "8fREYRW1lpIK5IBbTadXUESdjyTOMhnme/qNkH6FBsEQKb+b9YZ9wH9QwzE12zFEeXJos71pUWtCyTkA" +
            "0xtQwGJIaE70xFUV4TKKPNKAVmssWAL/xe3dwlVhMTEw==</Modulus><Exponent>AQAB</Exponent" +
            "></RSAKeyValue>";
    }
}
